package com.bto.solar.work.controller;

import com.bto.solar.work.common.R;
import com.bto.solar.work.entity.LeasePrjProjectProduct;
import com.bto.solar.work.service.BtoLeasePrjProjectService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 越秀-产品表 前端控制器
 * </p>
 *
 * @author adrian
 * @since 2023-08-09
 */
@RestController
@RequestMapping("/leasePrjProjectProduct")
public class LeasePrjProjectProductController {

    @Autowired
    private BtoLeasePrjProjectService leasePrjProjectService;

    /**
    * 产品方案列表展示
    * */
    @GetMapping("/get")
    public R<Object> getLeasePrjProjectProductList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                             @RequestParam(value = "isPage", required = false, defaultValue = "true") boolean isPage) {
        if (isPage) {
            PageInfo<LeasePrjProjectProduct> leasePrjProjectList = leasePrjProjectService.getLeasePrjProjectProductList(pageNum, pageSize);
            return R.ok(leasePrjProjectList , "产品方案数据请求成功");
        } else {
            List<LeasePrjProjectProduct> leasePrjProjectProducts = leasePrjProjectService.getLeasePrjProjectProductList();
            return  R.ok(leasePrjProjectProducts);
        }


    }

    /**
    * 产品方案
     * 新增
    * */
    @PostMapping("/add")
    public R<String> addLeasePrjProjectProduct(@RequestBody(required = true) @ApiParam("产品方案信息新增") LeasePrjProjectProduct leasePrjProjectProduct) {
         leasePrjProjectService.addLeasePrjProjectProduct(leasePrjProjectProduct);
         return R.ok();
    }

    /**
    * 产品方案
     * 修改
    * */
    @PutMapping("/update/{id}")
    public R updateLeasePrjProjectProduct(@RequestBody(required = true) @ApiParam("产品方案信息新增") LeasePrjProjectProduct leasePrjProjectProduct ,
                                                  @PathVariable("id")  Integer id)  {
        leasePrjProjectService.updateLeasePrjProjectProduct(id , leasePrjProjectProduct);
        return R.ok();
    }

}
